package cn.wxManage.goodsManage.controller;

import cn.common.common.model.ServerResponse;
import cn.wxManage.goodsManage.model.GoodsCart;
import cn.wxManage.goodsManage.service.IGoodsCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Zhang on 2019/1/22.
 */
@RestController
@RequestMapping("/goodsCart")
@Api(value="购物车方法",description = "购物车方法")
public class GoodsCartController {
    @Autowired
    IGoodsCartService iGoodsCartService;

    @ApiOperation(value="商品加入购物车", notes="商品加入购物车",produces = "application/json")
    @ApiImplicitParam(name = "GoodsCart", value = "购物车数据实体类",paramType ="body",dataType = "goodsCart")
    @PostMapping(value = "/addGoodsToCart")
    public ServerResponse<?> addGoodsToCart(@RequestBody GoodsCart goodsCart){
        return iGoodsCartService.addGoodsToCart(goodsCart);
    }

    @ApiOperation(value="调整购物车内商品数量", notes="调整购物车内商品数量",produces = "application/json")
    @ApiImplicitParam(name = "GoodsCart", value = "购物车数据实体类(只需要styleNum和id)",paramType ="body",dataType = "goodsCart")
    @PostMapping(value = "/updateCartNum")
    public ServerResponse<?> updateCartNum(@RequestBody GoodsCart goodsCart){
        return iGoodsCartService.updateCartNum(goodsCart);
    }

    @ApiOperation(value="从购物车内移除(type为goods-id值为goodsId,type为goodsStyle-id值为id)",
            notes="从购物车内移除",produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "若删除商品则传商品ID,若删除款式则传款式ID",
                    paramType ="query",dataType = "Integer"),
            @ApiImplicitParam(name = "type", value = "声明所传ID类型",
                    paramType ="query",dataType = "String")
    })
    @GetMapping(value = "/deleteGoodsFromCart")
    public ServerResponse<?> deleteGoodsFromCart(@RequestParam("id") Integer id,
                                                 @RequestParam("type") String type){
        return iGoodsCartService.deleteGoodsFromCart(id,type);
    }

    @ApiOperation(value="获取当前用户购物车", notes="获取当前用户购物车",produces = "application/json")
    @GetMapping(value = "/getCartList")
    public ServerResponse<?> getCartList(){
        return iGoodsCartService.getCartList();
    }

    @ApiOperation(value="获取当前用户当前购物车内商品数量", notes="获取当前用户当前购物车内商品数量",produces = "application/json")
    @GetMapping(value = "/getCartNum")
    public ServerResponse<?> getCartNum(){
        return iGoodsCartService.getCartNum();
    }
}
